package group2assignone.view.customer;

import group2assignone.func.UCCtoALAdapter;
import group2assignone.model.Customer;
import group2assignone.ucm.customer.UCUIEditCustomer;
import group2assignone.ucm.customer.UCUISearchFlights;
import group2assignone.ucm.customer.UCDeleteCustomer;
import group2assignone.ucm.UCLogout;
import group2assignone.view.OurView;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;

/**
 *This class handles the GUI for the welcome screen
 * when a user logs in to their account.
 */
public class CustomerWelcomeView extends OurView {

    private JLabel custLab;
    private JButton logout;
    private JButton searchFlights;
    private JButton editAccount;
    private JButton deleteAccount;
    private Customer customer;
    private int option;

    /**
     * sets the customer
     * @param cust
     */
    public CustomerWelcomeView(Customer cust) {
        customer = cust;
    }

    /**
     * Function to add the GUI components to the frame.
     */
    @Override
    public void addComponents() {

        setTitle("Customer Account Main Menu");
        logout = new JButton("Logout");
        custLab = new JLabel("Welcome " + customer.getUsername());
        northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.LINE_AXIS));
        custLab.setAlignmentX(JLabel.LEFT);
        logout.setAlignmentX(JButton.RIGHT);
        northPanel.add(custLab);
        northPanel.add(Box.createHorizontalGlue());
        northPanel.add(logout);
        northPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

        searchFlights = new JButton("Search Available Flights");
        editAccount = new JButton("Edit Account");
        deleteAccount = new JButton("Delete Account");
        centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.PAGE_AXIS));

        searchFlights.setAlignmentX(JButton.CENTER);
        editAccount.setAlignmentX(JButton.CENTER);
        deleteAccount.setAlignmentX(JButton.CENTER);
        centerPanel.add(Box.createRigidArea(new Dimension(10, 10)));
        centerPanel.add(searchFlights);
        centerPanel.add(Box.createRigidArea(new Dimension(10, 10)));
        centerPanel.add(editAccount);
        centerPanel.add(Box.createRigidArea(new Dimension(10, 10)));
        centerPanel.add(deleteAccount);

        centerPanel.setBorder(BorderFactory.createEmptyBorder(20, 10, 20, 20));
        northPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

        logout.addActionListener(new UCCtoALAdapter(new UCLogout(this)));
        searchFlights.addActionListener(new UCCtoALAdapter(new UCUISearchFlights(this, customer)));
        editAccount.addActionListener(new UCCtoALAdapter(new UCUIEditCustomer(this, customer)));
        deleteAccount.addActionListener(new UCCtoALAdapter(new UCDeleteCustomer(customer, this)));
    }

    /**
     * makes joptionpane for user to confirm whether they
     * want to delete their account
     * @return option selected
     */
    public int confirmDelete() {
        option = JOptionPane.NO_OPTION;
        option = JOptionPane.showConfirmDialog(
                this,
                "Are you sure you want to delete your account?",
                "Confirm",
                JOptionPane.YES_NO_OPTION);
        return option;
    }

    /**
     * makes joptoinpane notifying of successful deletion of their account
     */
    public void notifyDelete() {
        JOptionPane.showMessageDialog(this,
                "Your account was successfully deleted");
        dispose();
    }
}

    

